﻿
        <%@ Page language="vb" CodeFile="searchVehicle.aspx.vb" Inherits="searchVehicle_aspx_vb" %>

<%
        rowNumber = 0
        If (Request.QueryString("do")) = Nothing Then
            subDo = Request.QueryString("subDo")
        Over()
        'selectSub()
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='100%'>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='3'>SEARCH LEASE CONTRACT<hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='GarageBackUp.aspx?subDo=search' method='post' name='store_productsSearch'>")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Products:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='countryID' id='countryID' onchange=""set_child_listbox(this, document.store_productsSearch.partnerID,Product,'Products');"">")
        Response.Write("<option value=''> Select product  ")
       
        dbOpen()
        RecSet = Conn.Execute("select productID, product from tblProduct")
        Dim productID 
        If Not RecSet.EOF Then
            Do Until RecSet.EOF
                
                productID = RecSet.Fields("productID").Value
                product = RecSet.Fields("product").Value
                Response.Write("<option value='" & productID & "'> " & product & " ")
                RecSet.MoveNext()
            Loop
        End If
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        Response.Write("</tr>")
            
        Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Search'></td></tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("<td width='100'></td>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("<tr><td><br></td></tr>")
       ' Dim productID
        productID = Request.Form("productID")
        product = Request.Form("product")
        ' brandID = Request.Form("brandID")
        ' regnr = Request.Form("regnr")
        'vinNumber = Request.Form("vinNumber")
        ' contractNumber = Request.Form("contractNumber")
        If Len(productID) > 0 Then
            countryID = CLng(countryID)
            sqlCountryID = " AND v.countryID = " & countryID & ""
        End If
    If Len(partnerID) > 0 Then
        partnerID = CLng(partnerID)
        sqlPartnerID = " AND v.partnerID = " & partnerID & ""
    End If
    If Len(brandID) > 0 Then
        brandID = CLng(brandID)
        sqlBrandID = " AND v.brandID = " & brandID & ""
    End If
    regnr = CleanString(regnr)
    sqlRegnr = " AND v.regnr Like '%" & regnr & "%'"
    vinNumber = CleanString(vinNumber)
    sqlVinNumber = " AND v.vinNumber Like '%" & vinNumber & "%'"
    contractNumber = CleanString(contractNumber)
    sqlContractNumber = " AND v.contractNumber Like '%" & contractNumber & "%'"
    If Len(subDo) = 0 Then
        sqlCountryID = " And v.countryID = 1000"
    End If
        Response.Write("<tr>")
    Response.Write("<td valign='top' colspan='3'>")
    Response.Write("<table cellpadding='2' cellspacing='2' width='100%'>")
    Response.Write("<tr>")
    Response.Write("<td class='headline' colspan='10'>")
    Response.Write("SEARCH RESULT")
        Response.Write("<hr class='hrHeadline'>")
    Response.Write("</td>")
    Response.Write("</tr>")
    dbOpen()
    sql = "Select Top(50)  v.vehicleID, v.regnr, v.vinNumber, v.contractNumber, v.date AS tblVehicleDate, v.completed, v.active, b.brandID, m.modelID,p.product, VehicleInfo.Marke,VehicleInfo.Modell, b.brand, m.model,pl.priceListID, d.dealer, c.country  From (((((tblVehicle v Full JOIN tblProduct p ON p.productID = v.productID) full join tblPriceList as pl on pl.priceListID = v.priceListID full Join VehicleInfo on vehicleInfo.Typkod = pl.Typkod Full JOIN tblBrand b ON b.brandID = v.brandID) Full JOIN tblModel m ON m.modelID = v.modelID) Full JOIN tblDealer d ON d.dealerID = v.dealerID) Full JOIN tblCountry c ON c.countryID = v.countryID) Where v.vehicleID > 0" & sqlCountryID & sqlPartnerID & sqlBrandID & sqlRegnr & sqlVinNumber & sqlContractNumber & " ORDER BY v.vehicleID Desc"
    RecSet = Conn.Execute(sql)
    If RecSet.EOF Then
        Response.Write("<tr><td><font color='red'>No lease contracts found.</font></td></tr>")
    Else
        Response.Write("<tr bgcolor='#eeeeee'>")
        Response.Write("<td class='formBold'>Car dealer</td>")
        Response.Write("<td class='formBold'>Contract number</td>")
        Response.Write("<td class='formBold'>Licence number</td>")
        Response.Write("<td class='formBold'>VIN-number</td>")
        Response.Write("<td class='formBold'>Car make</td>")
        Response.Write("<td class='formBold'>Product</td>")
        Response.Write("<td class='formBold'>Country</td>")
        Response.Write("<td class='formBold'>Status</td>")
        Response.Write("<td class='formBold'>First created</td>")
        Response.Write("<td class='formBold'></td>")
        Response.Write("</tr>")
        rowNumber = 1
        Do Until RecSet.EOF
            vehicleID = RecSet.Fields("vehicleID").Value
            regnr = RecSet.Fields("regnr").Value
            vinNumber = RecSet.Fields("vinNumber").Value
            contractNumber = RecSet.Fields("contractNumber").Value
            tblVehicleDate = RecSet.Fields("tblVehicleDate").Value
            completed = RecSet.Fields("completed").Value
            active = RecSet.Fields("active").Value
            product = RecSet.Fields("product").Value
            brand = RecSet.Fields("brand").Value
            model = RecSet.Fields("model").Value
            dealer = RecSet.Fields("dealer").Value
            country = RecSet.Fields("country").Value
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & dealer & "</td>")
                Response.Write("<td>" & contractNumber & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td>" & brand & " " & model & "</td>")
                Response.Write("<td>" & product & "</td>")
                Response.Write("<td>" & country & "</td>")
                Response.Write("<td>" & status & "</td>")
                Response.Write("<td>" & Left(tblVehicleDate, 10) & "</td>")
                Response.Write("<td><a href='editVehicle.aspx?vehicleID=" & vehicleID & "'>view details</a></td>")
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
    End If
    RecSet.Close()
    RecSet = Nothing
    dbClose()
    Response.Write("<tr><td colspan='10'><hr class='hrHeadline'></td></tr>")
    Response.Write("</table>")
    Response.Write("</td>")
    Response.Write("</tr>")
    Response.Write("</table>")
    Under()
    End If
%>




